$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'supp/sellerinfo/list',
        datatype: "json",
        colModel: [
            { label: '操作', name: 'option', index: 'option', width: 70 ,align: 'center', title:false,
                formatter:function(value, options, row){
                    var actions = [];
                    if (row.sellerState == '1' || row.sellerState == '2'){
                        // 新商户、未通过
                        actions.push('<a href="javascript:void(0);" onclick="return goAudit('+ options.rowId +');">审核</a>') ;
                        actions.push('&nbsp;|&nbsp;');
                    }
                    actions.push('<a href="javascript:void(0);" onclick="return edit('+ options.rowId +');">编辑</a>') ;
                    if (row.sellerState == 3&&row.disabled==0) {
                        if (row.sellerType == 0 && row.copyGoods == 0){
                            actions.push('<a href="javascript:void(0);" onclick="return vm.copyGoods('+ options.rowId +');">初始化商品</a>') ;
                        }
                        actions.push('<a href="javascript:void(0);" onclick="return vm.freeze('+ options.rowId +');">冻结</a>') ;
                    }
                    if (row.sellerState == 3&&row.disabled==1) {
                        actions.push('<a href="javascript:void(0);" onclick="return vm.unfreeze('+ options.rowId +');">解冻</a>') ;
                    }
                    return actions.join(' ');
                }
            },
            { label: '商家ID', name: 'sellerId', index: 'seller_id', key: true, width: 40,align: 'center'},
            { label: '状态', name: 'sellerState', index: 'seller_state', width: 50,align: 'center',
                formatter:function(value, options, row){
                    // 0:未申请，1：新商户，2：未通过，3：已审核
                    if (value == '1'){
                        return '新商户';
                    }else if (value == '2'){
                        return '未通过';
                    }else if (value == '3'){
                        return '已审核';
                    }
                    return '';
            	}
            },
            { label: '商家名', name: 'sellerName', index: 'seller_name', width: 120 ,align: 'center'},
            { label: '商户类型', name: 'sellerType', index: 'seller_name', width: 50 ,align: 'center',
                formatter:function(value, options, row){
                    // 商户类型 0：供应商 1：工厂
                    if (value == 0){
                        return '商户';
                    }else if (value == 1){
                        return '工厂';
                    }
                    return '';
                }
            },
            { label: '联系人', name: 'name', index: 'name', width: 50 ,align: 'center'},
            { label: '电话号码', name: 'sellerMobile', index: 'seller_mobile', width: 80 ,align: 'center'},
            { label: 'QQ', name: 'sellerQq', index: 'seller_qq', width: 80 ,align: 'center'},
            { label: '地区', name: 'area', index: 'area', width: 80 ,align: 'center'},
            { label: '地址', name: 'addr', indqex: 'addr', width: 120 ,align: 'center'},
            { label: '创建时间', name: 'createtime', index: 'createtime', width: 100 ,align: 'center'},
            { label: '是否冻结', name: 'disabled', index: 'disabled', width: 50 ,align: 'center',
                formatter:function(value, options, row){
                    if (value == 0){
                        return '未冻结';
                    }else if (value == 1){
                        return '冻结';
                    }else{
                        return '';
                    }
                }},
            { label: '前端状态', name: 'display', index: 'display', width: 50 ,align: 'center',
                formatter:function(value, options, row){
                    // 审核通过
                    if (row.sellerState == '3'){
                        // 0:不显示，1：显示
                        if (value == '0'){
                            return '<a href="javascript:;" onclick="return updateView('+ options.rowId +');">不显示</a>';
                        }else if (value == '1'){
                            return '<a href="javascript:;" onclick="return updateView('+ options.rowId +');">显示</a>';
                        }
                    }else {
                        return value == '0' ? '不显示' : '显示';
                    }
                }
			},
            { label: '自提状态', name: 'pickUp', index: 'pick_up', width: 50 ,align: 'center',
                formatter:function(value, options, row){
                    if (value == 0){
                        return '<a href="javascript:;" onclick="return updatePickUp('+ options.rowId +');">不自提</a>';
                    }else {
                        return '<a href="javascript:;" onclick="return updatePickUp('+ options.rowId +');">自提</a>';
                    }
                }
            },
            { label: '初始化状态', name: 'copyGoods', index: 'copy_goods', width: 50 ,align: 'center',
                formatter:function(value){
                    return value == 0 ? '否':'是';
                }
            },
            { label: '业务员', name: 'salesman', index: 'salesman', width: 50 , align: 'center',
                formatter:function(value, options, row){
                    if (isBlank(value)){
                        value = '添加';
                    }
                    return '<a href="javascript:void(0);" onclick="return salesmanShow('+ options.rowId +');">'+ value +'</a>';
                }
            },
            { label: '业务员电话', name: 'salesmanMobile', index: 'salesman_mobile', width: 60 ,align: 'center'},
            { label: '备注', name: 'remarks', index: 'remarks', width: 80 ,align: 'center',
                formatter:function(value, options, row){
                    if (isBlank(value)){
                        value = '添加';
                    }
                    return '<a href="javascript:void(0);" onclick="return remarksShow('+ options.rowId +');">'+ value +'</a>';
                }
            },
            { label: '审核人', name: 'auditName', index: 'audit_name', width: 50 ,align: 'center'},
            { label: '审核时间', name: 'auditTime', index: 'audit_time', width: 100 ,align: 'center'},
        ],
		viewrecords: true,
        height: window.innerHeight - 120,
        rowNum: 25,
		rowList : [25,50,75],
        rownumbers: true, 
        rownumWidth: 40,
        autowidth:true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount",
            userdata: "userData"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
            var userData = $("#jqGrid").jqGrid('getGridParam', 'userData');
            // 省市区
            var regions = userData.regions;
            var options = JSON.parse(regions);
            vm.options = options;
            // 审核人
            var auditNames = userData.auditNames;
            vm.auditNames = auditNames;
            // 商家类型
            var sellerTypeEnum = userData.sellerTypeEnum;
            vm.sellerTypeEnum = sellerTypeEnum;
        }
    });
    // 显示序号
    $("#jqGrid").jqGrid('setLabel',0, '序号', '{width:80}');
});

/**
 * 商家自提/不自提状态切换
 */
function updatePickUp(rowId) {
    var rowData = $("#jqGrid").jqGrid('getRowData', rowId);
    var pickUpStr = $(rowData.pickUp).text();
    var msg = pickUpStr == '自提' ? '是否设置为不自提？' : '是否设置为自提？';
    var pickUpVal = pickUpStr == '自提' ? '0' : '1';
    confirm(msg, function(){
        $.ajax({
            type: "GET",
            url: baseURL + "supp/sellerinfo/updatePickUp",
            contentType: "application/json",
            data: {
                'sellerId': rowData.sellerId,
                'pickUp': pickUpVal
            },
            success: function(r){
                if(r.code == 0){
                    alert('操作成功', function(index){
                        vm.reload();
                    });
                }else{
                    alert(r.msg);
                }
            }
        });
    });
}

/**
 * 商家显示/不显示状态切换
 */
function updateView(rowId) {
    var rowData = $("#jqGrid").jqGrid('getRowData', rowId);
    var sellerName = rowData.sellerName;
    var sellerId = rowData.sellerId;
    var displayStr = $(rowData.display).text();
    var displayVal = displayStr == '不显示' ? '1' : '0';
    var msg = displayVal == '1' ? '是否显示商家' : '是否隐藏商家';
    msg += "&nbsp;<span class='text-primary'>"+ sellerName +"</span>？";
    confirm(msg, function(){
        $.ajax({
            type: "GET",
            url: baseURL + "supp/sellerinfo/updateView",
            contentType: "application/json",
            data: {
                'sellerId': rowData.sellerId,
                'display': displayVal
            },
            success: function(r){
                if(r.code == 0){
                    alert('操作成功', function(index){
                        vm.reload();
                    });
                }else{
                    alert(r.msg);
                }
            }
        });
    });
}

/**
 * 录入业务员、业务员电话信息
 */
function salesmanShow(rowId) {
    var rowData = $("#jqGrid").jqGrid('getRowData', rowId);
    if (rowData.sellerId != vm.sm.sellerId){
        vm.sm.salesman = '';
    }
    var salesmanVal = $(rowData.salesman).text();
    if (salesmanVal != '添加') {
        vm.sm.salesman = salesmanVal;
    }
    vm.sm.sellerId = rowData.sellerId;
    vm.sm.sellerName = rowData.sellerName;
    vm.sm.salesmanMobile = rowData.salesmanMobile;
    vm.smFormVisible = true;
}

/**
 * 添加备注
 */
function remarksShow(rowId) {
    vm.rm.sellerId = rowId;
    var rowData = $("#jqGrid").jqGrid('getRowData', rowId);
    vm.rm.sellerName = rowData.sellerName;
    vm.remarksShow(rowId);
}

/**
 * 商家编辑
 */
function edit(rowId) {
    var rowData = $("#jqGrid").jqGrid('getRowData', rowId);
    vm.edit(rowData.sellerId);
}

/**
 * 商家审核
 */
function goAudit(rowId) {
    var rowData = $("#jqGrid").jqGrid('getRowData', rowId);
    vm.goAudit(rowData.sellerId);
}

/**
 * 省市区级联选择
 * @param val
 * @param opt
 */
function getCascaderObj(val, opt) {
    return val.map(function (value, index, array) {
        for (var itm in opt) {
            if (opt[itm].value == value) {
                var label = opt[itm].label;
                opt = opt[itm].children; return label;
            }
        }
        return null;
    });
}

var vm = new Vue({
	el:'#rrapp',
	data:{
	    /* 查询字段 */
        q:{
            sellerName: '',
            sellerId: '',
            salesman: '',
            area: '',
            auditName: '',
            display: '',
            beginCreatetime: '',
            endCreatetime: '',
            sellerType: '',
            sellerState: '',
            sellerQq: '',
            sellerMobile: '',
        },
        /* 审核人 */
        auditNames: [],
        /* 商家类型 */
        sellerTypeEnum: [],
        /* 模块显示、隐藏 */
		showList: true,
        showListUpdate: false,
        showListAudit: false,
        /* 商户信息实体 */
		sellerInfo: {},
        /* 支持服务 */
        supportServiceArr:[],
        /* 商户图册 */
        sellerImageUrlArr:[],
        /* 连锁店 */
        mainStores: [],
        /* 省市区data */
        options: [],
        /* 省市区回显 */
        areaCascader: [],
        /* 录入业务员 */
        smFormVisible: false,
        formLabelWidth: '100px',
        sm:{
            sellerId: '',
            sellerName: '',
            salesman: '',
            salesmanMobile: ''
        },
        /* 录入备注 */
        rmTableVisible: false,
        remarks:[],
        rmFormVisible: false,
        rm: {
            sellerId: '',
            sellerName: '',
            remarks: ''
        },
        /* 总店设置 */
        msFormVisible: false,
        ms: {
            mainStoreName: '',
        },
        /* 营业执照识别、工商数据检测 */
        ocrResultVisible: false,
        ocrResult: {},
        checkResultVisible: false,
        checkResult: {},
        /* 批量初始化商品 */
        loading: false,
        copyGoodsVisible: false,
        copyGoodsSellerIds: null,
	},
    mounted: function(){
        this.filesUploadInit();
    },
	methods: {
	    checkBeginDate: function () {
            WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false, onpicking:function (dp) {
                    vm.q.beginCreatetime = dp.cal.getNewDateStr();
            }})
        },
        checkEndDate: function () {
            WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false, onpicking:function (dp) {
                    vm.q.endCreatetime = dp.cal.getNewDateStr();
                }})
        },
        /* 批量初始化商品 */
        copyGoodsBatch: function () {
            if (isBlank(this.copyGoodsSellerIds)){
                return false;
            }
            var ids = this.copyGoodsSellerIds.split(',');
            $.ajax({
                type: "POST",
                timeout : 36000000,
                url: baseURL + "supp/sellerinfo/sellerCopyGoodsBatch",
                contentType: "application/json",
                data: JSON.stringify(ids),
                success: function(r){
                    if(r.code == 0){
                        alert("初始化成功");
                        vm.copyGoodsVisible = false;
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        /* 商户全部初始化 */
        copyGoodsBatchAll: function () {
            this.$confirm('是否初始化所有商户商品?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                callback: function (f) {
                    if (f == 'confirm'){
                        $.ajax({
                            type: "POST",
                            url: baseURL + "supp/sellerinfo/sellerCopyGoodsBatchAll?nums=0",
                            contentType: "application/json",
                            data: {},
                            success: function(r){
                                if(r.code == 0){
                                    alert("初始化成功");
                                }else{
                                    alert(r.msg);
                                }
                            }
                        });
                    }
                }
            })
        },
        /* 初始化oss上传 */
        filesUploadInit: function () {
            $.files_up_oss({
                id: ["upload1", 'upload2', 'upload3'],// 按钮id
                url: "/sys/oss/getSignature",
                dir: "seller/sellerimage/",
                file_type: "jpg,png,gif,psd,ai,cdr,eps,ppt,word,excel,pdf,tiff,rar,zip,7z",
                size: "100mb",//mb
                view_url: "https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/"
            }, function (index_number, json) {
                console.info('files_up_oss[index_number:' + index_number + '],[json:'+ json +']');
                if (json.Status == 'OK'){
                    var name = json.oldFilename.replace(/'/g, '');
                    var postData = {
                        sellerId: vm.sellerInfo.sellerId,
                        imageType: index_number + 1,
                        otherAccessory: {
                            type: 0,
                            imageUrl: json.filename,
                            name: name,
                            size: json.size,
                            fileType: json.mimeType
                        }
                    }

                    $.ajax({
                        type: "POST",
                        url: baseURL + "supp/sellerinfo/saveImage",
                        contentType: "application/json",
                        data: JSON.stringify(postData),
                        success: function(r){
                            if(r.code == 0){
                                vm.getInfo(vm.sellerInfo.sellerId);
                            }else{
                                alert(r.msg);
                            }
                        }
                    });
                }else {
                    alert("OSS上传失败，请联系后台管理员！");
                }
            });
        },
        /* 图片预览初始化 */
        filesViewerInit: function () {
            $('#updateViewer').viewer();
            $('#auditViewer').viewer();
        },
        /* 获取经纬度 */
        generateLongLat: function () {
            var area = vm.sellerInfo.area;
            if (isBlank(area)){
                alert("请填写公司地址！");
                return;
            }

            var addr = vm.sellerInfo.addr;
            if (isBlank(addr)){
                alert("请填写详细地址！");
                return;
            }
            addr = area + addr;
            $.get(baseURL + "supp/sellerinfo/generateLongLat?addr=" + addr, function(r){
                var result = r.result;
                if (result.status = 'success'){
                    var data = result.data.split(',');
                    vm.sellerInfo.longitude = data[0];
                    vm.sellerInfo.latitude = data[1];
                }
            });
        },
        /* 业务员录入 */
        salesmanAdd: function () {
            $.ajax({
                type: "POST",
                url: baseURL + "supp/sellerinfo/addSalesman",
                contentType: "application/json",
                data: JSON.stringify(vm.sm),
                success: function(r){
                    if(r.code == 0){
                        vm.smFormVisible = false;
                        vm.reload();
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        /* 详情 */
        getInfo: function(sellerId){
            vm.ocrResultVisible = false;
            vm.checkResultVisible = false;
            $.get(baseURL + "supp/sellerinfo/info/"+sellerId, function(r){
                vm.sellerInfo = r.sellerInfo;

                /* 支持服务 */
                var supportService = r.sellerInfo.supportService;
                if (!isBlank(supportService)){
                    vm.supportServiceArr = supportService.split(",");
                }

                /* 省市区 */
                var regionPath = r.sellerInfo.regionPath;
                if (!isBlank(regionPath)){
                    // 字符型数组
                    var regionPathStringArr = regionPath.substring(1, regionPath.length-1).split(",");
                    // 整形数组
                    var regionPathIntArr = regionPathStringArr.map(function(data){
                        return +data;
                    });
                    vm.areaCascader = regionPathIntArr;
                }

                /* 审核状态 */
                if (vm.sellerInfo.sellerState != '3'){
                    vm.sellerInfo.sellerState = '';
                }

                /* 商户图册 */
                vm.sellerImageUrlArr = [];
                var sellerImageUrl = r.sellerInfo.sellerImageUrl;
                if (!isBlank(sellerImageUrl)){
                    $.get(baseURL + "otherAccessory/otheraccessory/imageslist?imageUrl=" + sellerImageUrl, function(r2){
                        vm.sellerImageUrlArr = r2.list;
                    });
                }

                /* 连锁店信息 */
                $.get(baseURL + "supp/sellerinfo/mainStore?sellerId="+sellerId+"&mainSellerId="+r.sellerInfo.mainSellerId, function(r2){
                    vm.mainStores = r2.list;
                    Vue.nextTick(function () {
                        $('#updateStoresViewer').viewer();
                        $('#auditStoresViewer').viewer();
                    });
                });
                vm.filesViewerInit();
            });
        },
        /* 查询重置 */
        reset: function () {
            vm.q.sellerName = '';
            vm.q.sellerId = '';
            vm.q.salesman = '';
            vm.q.area = '';
            vm.q.auditName = '';
            vm.q.display = '';
            vm.q.beginCreatetime = '';
            vm.q.endCreatetime = '';
            vm.q.sellerType = '';
            vm.q.sellerState = '';
            vm.q.sellerQq = '';
            vm.q.sellerMobile = '';
            vm.reload();
        },
        /* 备注展示 */
        remarksShow: function (sellerId) {
            /* 连锁店信息 */
            $.get(baseURL + "supp/supplierremarks/remarks?srSupplierId="+ sellerId, function(r){
                if (r.list.length > 0){
                    vm.remarks = r.list;
                    vm.rmTableVisible = true;
                }else {
                    vm.rmFormVisible = true
                }
            });

        },
        /* 备注录入 */
        remarkAdd: function () {
            $.ajax({
                type: "GET",
                url: baseURL + "supp/sellerinfo/addRemarks",
                contentType: "application/json",
                data: {
                    'sellerId': vm.rm.sellerId,
                    'remarks': vm.rm.remarks
                },
                success: function(r){
                    if(r.code == 0){
                        vm.rmFormVisible = false;
                        vm.rmTableVisible = false;
                        vm.rm.remarks = '';
                        vm.reload();
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        edit: function(sellerId){
            vm.showList = false;
            vm.showListUpdate = true;
            vm.title = "编辑";
            vm.getInfo(sellerId)
        },
        goAudit: function(sellerId){
            vm.showList = false;
            vm.showListAudit = true;
            vm.title = "审核";
            vm.getInfo(sellerId)
        },
        audit: function () {
            // 验证参数mainStores
            // if (!vm.validator()){
            //     return false;
            // }
            var sellerState = vm.sellerInfo.sellerState;
	        if (isBlank(sellerState) || sellerState == '1'){
                alert('请选择审核结果');
                return false;
            }
            if (sellerState == '2'){
	            var overruleRemarks = vm.sellerInfo.overruleRemarks;
	            if (isBlank(overruleRemarks)){
                    alert("审核备注不能为空");
                    return false;
                }
            }

            var postData = {
                sellerId: vm.sellerInfo.sellerId,
                sellerState: vm.sellerInfo.sellerState,
                overruleRemarks: vm.sellerInfo.overruleRemarks
            }
            $.ajax({
                type: "POST",
                url: baseURL + 'supp/sellerinfo/audit',
                contentType: "application/json",
                data: JSON.stringify(postData),
                success: function(r){
                    if(r.code === 0){
                        alert(r.msg, function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        /* 删除商户图片 */
        removeSellerImage: function (id) {
            this.$confirm('确认删除该商户图片吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                callback: function (f) {
                    if (f == 'confirm'){
                        $.ajax({
                            type: "GET",
                            url: baseURL + 'supp/sellerinfo/removeSellerImage?sellerId='+ vm.sellerInfo.sellerId +'&id='+id,
                            contentType: "application/json",
                            data: null,
                            success: function(r){
                                if(r.code === 0){
                                    vm.getInfo(vm.sellerInfo.sellerId);
                                }else{
                                    alert(r.msg);
                                }
                            }
                        });
                    }
                }
            })
        },
        /* 商户营业执照、工商数据检测 */
        sellerInfoValidity: function () {
            var sellerState = vm.sellerInfo.sellerState;
            if (isBlank(sellerState) || sellerState == '1'){
                alert('请选择审核结果');
                return false;
            }
            if (sellerState == '2'){
                vm.audit();
                return false;
            }
            vm.checkResultVisible = true;
            $.get(baseURL + "supp/sellerinfo/sellerInfoValidity?sellerId="+ vm.sellerInfo.sellerId, function(r){
                if(r.code === 0){
                    var ocrBoolean = r.ocrBoolean;
                    var checkBoolean = r.checkBoolean;
                    if (ocrBoolean && checkBoolean){
                        vm.audit();
                    }else{
                        var ocrMessage = r.ocrMessage;
                        var checkMessage = r.checkMessage;
                        var ocrResult = r.ocrResult;
                        var checkResult = r.checkResult;
                        if (typeof ocrResult != 'undefined') {
                            vm.ocrResult = ocrResult;
                            vm.ocrResultVisible = true;
                        }
                        if (typeof checkResult != 'undefined') {
                            vm.checkResult = checkResult;
                            vm.checkResultVisible = true;
                        }
                        alert(ocrMessage + '；<br/>' + checkMessage + "；");
                    }
                }else{
                    alert(r.msg);
                }
            });
        },
		query: function () {
			vm.reload();
		},
		saveOrUpdate: function (event) {
            // 验证参数
	        if (!vm.validator()){
                return false;
            }
            vm.sellerInfo.supportService = vm.supportServiceArr.join(',');
            var url = vm.sellerInfo.sellerId == null ? "supp/sellerinfo/save" : "supp/sellerinfo/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.sellerInfo),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
        mainStoreShow: function () {
            vm.msFormVisible = true;
            vm.ms.mainStoreName = vm.mainStores[0].sellerName;
        },
        setMainStore: function () {
            $.ajax({
                type: "GET",
                url: baseURL + 'supp/sellerinfo/setMainStore',
                contentType: "application/json",
                data: {
                    sellerId: vm.sellerInfo.sellerId,
                    mainStoreId: vm.sellerInfo.mainStoreId
                },
                success: function(r){
                    vm.msFormVisible = false;
                    if(r.code === 0){
                        alert('操作成功', function (index) {
                            vm.getInfo(vm.sellerInfo.sellerId);
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
		del: function (event) {
			var sellerIds = getSelectedRows();
			if(sellerIds == null){
				return ;
			}
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "supp/sellerinfo/delete",
                    contentType: "application/json",
				    data: JSON.stringify(sellerIds),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		reload: function (event) {
			vm.showList = true;
            vm.showListUpdate = false;
            vm.showListAudit = false;
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{
                	'sellerName': vm.q.sellerName,
                	'sellerId': vm.q.sellerId,
                    'salesman': vm.q.salesman,
                    'area': vm.q.area,
                    'auditName': vm.q.auditName,
                    'display': vm.q.display,
                    'beginCreatetime': vm.q.beginCreatetime,
                    'endCreatetime': vm.q.endCreatetime,
                    'sellerType': vm.q.sellerType,
                    'sellerState': vm.q.sellerState,
                    'sellerQq': vm.q.sellerQq,
                    'sellerMobile': vm.q.sellerMobile,
				},
                page: 1
            }).trigger("reloadGrid");
		},
        validator: function () {
            if (isBlank(vm.sellerInfo.sellerName)){
                alert("供应商名称不能为空");
                return false;
            }
            if (isBlank(vm.sellerInfo.doorheadName)){
                alert("门头名称不能为空");
                return false;
            }
            if (isBlank(vm.sellerInfo.name)){
                alert("联系人不能为空");
                return false;
            }
            if (isBlank(vm.sellerInfo.sellerMobile)){
                alert("手机号码不能为空");
                return false;
            }
            if (isBlank(vm.sellerInfo.sellerEmail)){
                alert("邮箱不能为空");
                return false;
            }
            if (isBlank(vm.sellerInfo.area)){
                alert("公司地址不能为空");
                return false;
            }
            if (isBlank(vm.sellerInfo.addr)){
                alert("详细地址不能为空");
                return false;
            }
            if (isBlank(vm.sellerInfo.longitude) || isBlank(vm.sellerInfo.latitude)){
                alert("经纬度不能为空");
                return false;
            }
            return true;
        },
        handleItemChange: function(val) {
	        var values = val.join(',').split(',');
            var areaId = values[val.length-1];
            vm.sellerInfo.areaId = areaId;
            var lableObj = getCascaderObj(val, vm.options);
            var lable = lableObj.join(',').replace(new RegExp(',', 'g'), ' ');
            vm.sellerInfo.area = lable;
        },
        copyGoods: function (sellerId) {
            var self = this;
            this.$confirm('是否确认初始化商品信息?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                callback: function (f) {
                    if (f == 'confirm'){
                        self.loading = true;
                        $.ajax({
                            type: "GET",
                            timeout : 3600000,
                            url: baseURL + "supp/sellerinfo/copyGoods/" + sellerId,
                            contentType: "application/json",
                            data: null,
                            success: function(r){
                                self.loading = false;
                                if(r.code == 0){
                                    alert('初始化成功!', function(index){
                                        vm.reload();
                                    });
                                }else{
                                    alert(r.msg);
                                }
                            }
                        });
                    }
                }
            })
        },
        freeze(sellerId) {
            $.get(baseURL + "supp/sellerinfo/freeze/"+sellerId, function(r){
                if(r.code === 0){
                    alert('冻结成功!', function(index){
                        vm.reload();
                    });
                }else{
                    alert(r.msg)
                }
            });
        },
        unfreeze(sellerId) {
            $.get(baseURL + "supp/sellerinfo/unfreeze/"+sellerId, function(r){
                if(r.code === 0){
                    alert('解冻成功!', function(index){
                        vm.reload();
                    });
                }
            });
        }
	}
});

